; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -passes=loop-unroll -S < %s | FileCheck %s

define i32 @test(i32 %a, i32 %b, i32 %c) optsize {
; CHECK-LABEL: @test(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[REF_TMP:%.*]] = alloca [3 x i32], align 4
; CHECK-NEXT:    store i32 [[A:%.*]], ptr [[REF_TMP]], align 4
; CHECK-NEXT:    [[ARRAYINIT_ELEMENT:%.*]] = getelementptr inbounds [3 x i32], ptr [[REF_TMP]], i64 0, i64 1
; CHECK-NEXT:    store i32 [[B:%.*]], ptr [[ARRAYINIT_ELEMENT]], align 4
; CHECK-NEXT:    [[ARRAYINIT_ELEMENT1:%.*]] = getelementptr inbounds [3 x i32], ptr [[REF_TMP]], i64 0, i64 2
; CHECK-NEXT:    store i32 [[C:%.*]], ptr [[ARRAYINIT_ELEMENT1]], align 4
; CHECK-NEXT:    [[CMP_I_I_I3:%.*]] = icmp slt i32 [[A]], [[B]]
; CHECK-NEXT:    [[SPEC_SELECT_I_I4:%.*]] = select i1 [[CMP_I_I_I3]], ptr [[ARRAYINIT_ELEMENT]], ptr [[REF_TMP]]
; CHECK-NEXT:    [[INCDEC_PTR_I_I5:%.*]] = getelementptr inbounds [3 x i32], ptr [[REF_TMP]], i64 0, i64 2
; CHECK-NEXT:    br label [[LOOP:%.*]]
; CHECK:       loop:
; CHECK-NEXT:    [[DOTPRE:%.*]] = load i32, ptr [[SPEC_SELECT_I_I4]], align 4
; CHECK-NEXT:    [[DOTPRE2:%.*]] = load i32, ptr [[INCDEC_PTR_I_I5]], align 4
; CHECK-NEXT:    [[CMP_I_I_I:%.*]] = icmp slt i32 [[DOTPRE]], [[DOTPRE2]]
; CHECK-NEXT:    [[SPEC_SELECT_I_I:%.*]] = select i1 [[CMP_I_I_I]], ptr [[INCDEC_PTR_I_I5]], ptr [[SPEC_SELECT_I_I4]]
; CHECK-NEXT:    [[TMP1:%.*]] = load i32, ptr [[SPEC_SELECT_I_I]], align 4
; CHECK-NEXT:    ret i32 [[TMP1]]
;
entry:
  %ref.tmp = alloca [3 x i32], align 4
  store i32 %a, ptr %ref.tmp, align 4
  %arrayinit.element = getelementptr inbounds [3 x i32], ptr %ref.tmp, i64 0, i64 1
  store i32 %b, ptr %arrayinit.element, align 4
  %arrayinit.element1 = getelementptr inbounds [3 x i32], ptr %ref.tmp, i64 0, i64 2
  store i32 %c, ptr %arrayinit.element1, align 4
  %add.ptr.i.i = getelementptr inbounds [3 x i32], ptr %ref.tmp, i64 0, i64 3
  %cmp.i.i.i3 = icmp slt i32 %a, %b
  %spec.select.i.i4 = select i1 %cmp.i.i.i3, ptr %arrayinit.element, ptr %ref.tmp
  %incdec.ptr.i.i5 = getelementptr inbounds [3 x i32], ptr %ref.tmp, i64 0, i64 2
  br label %loop

loop:          ; preds = %entry, %loop
  %incdec.ptr.i.i7 = phi ptr [ %incdec.ptr.i.i5, %entry ], [ %incdec.ptr.i.i, %loop ]
  %spec.select.i.i6 = phi ptr [ %spec.select.i.i4, %entry ], [ %spec.select.i.i, %loop ]
  %.pre = load i32, ptr %spec.select.i.i6, align 4
  %.pre2 = load i32, ptr %incdec.ptr.i.i7, align 4
  %cmp.i.i.i = icmp slt i32 %.pre, %.pre2
  %spec.select.i.i = select i1 %cmp.i.i.i, ptr %incdec.ptr.i.i7, ptr %spec.select.i.i6
  %incdec.ptr.i.i = getelementptr inbounds i32, ptr %incdec.ptr.i.i7, i64 1
  %cmp1.i.i = icmp eq ptr %incdec.ptr.i.i, %add.ptr.i.i
  br i1 %cmp1.i.i, label %exit, label %loop

exit:           ; preds = %loop
  %0 = load i32, ptr %spec.select.i.i, align 4
  ret i32 %0
}
